import { store } from "@/store";
import { defineStore } from "pinia";
import { storageLocal } from "@pureadmin/utils";
import { DATA_DASHBOARD_THEME_Map } from "@/constant/index";
import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange";
import { getConfig } from "@/config";
import { darken } from "@pureadmin/theme/dist/browser-utils";
import { log } from "console";
export const useDataDashboardThemeStore = defineStore({
  id: "data-dashboard-them",
  state: () => ({
    dataDashboardThem: null,
    dataDashboardType: 1, //当前大屏类型1:单位大屏 2:项目大屏 3:监管大屏
    dataDashboardMenuId: 1, //当前大屏菜单id
    dataDashboardButtonId: 1, //底部按钮选中id
    dataDashboardButtonIdsa:null, //底部按钮选中记录 切换时返回去
    dataDashboardProjectId: null, //当前项目id
    dataDashboardIsHidden: 1, //是否隐藏左右两边的内容 1:显示 2:隐藏
    systematicId: null, //系统id
    all: null,
    systemidparent: null, //项目系统父id
    showverviewalrm: 1, //概览告警 1:总览 2:告警
    overviewCenterPoint: [], //监管大屏中心点位
    drawmapid: 0, //当前图纸id
    workfresh: 0, //工单刷新
    systemShow: 0, //0:不显示系统选择框 1:显示两级系统选择框 2显示一级系统选择框
    mapTheme: "",
    systeminfo: {
      systemName: "",
      selectIndex: "",
      selectIndextwo: "",
      systemlist: [],
      systemlistson: []
    }, //选中的系统信息
    projectInfo: {
      indexMode: 1
    }, //项目背景默认模式 1:地图 2:平面图 3:vr 4
    unityInfo: {
      logo: ""
    }, //项目背景默认模式 1:地图 2:平面图 3:vr 4
    dataDashboardSidebar: {
      id: 1,
      name: null,
      componentleft: "",
      componentright: ""
    }, // //两侧内容

    building: {
      /** 建筑信息 */
      buildingInfo: null,
      /** 当前选中图纸信息 */
      drawingInfo: null,
      /** 当前选中图纸id */
      checkedDrawingId: null
    },

    /** 是否关闭自动弹窗 */
    closeAutoPopUp: false,
    /** 是否开启提示音 */
    openSound: false
  }),
  actions: {
    /** 获取大屏主题 */
    getDataDashboardThem() {
      if (!this.dataDashboardThem) {
        this.setDataDashboardThem(storageLocal().getItem("dataDashboardThem"));
      }
      return this.dataDashboardThem;
    },
    /** 设置大屏主题 默认值为default */
    setDataDashboardThem(
      theme: DATA_DASHBOARD_THEME_Map = DATA_DASHBOARD_THEME_Map.default
    ) {
      !theme && (theme = DATA_DASHBOARD_THEME_Map.default);
      console.log(document.documentElement.classList,'classList')
      let classList = document.documentElement.classList;
      classList.forEach(item => {
        if (item.startsWith("data-dashboard-")) {
          classList.remove(item);
        }
      });
      if (!classList.contains(`dark`)) {
        document.documentElement.classList.add(`dark`);
      }
      // const { EpThemeColor } = getConfig();
        const EpThemeColor = "#4583FF";
      try {
        useDataThemeChange().setEpThemeColor(EpThemeColor);
      } catch (e) {
        console.log(e)
      }
      document.documentElement.style.setProperty(
        "--el-color-primary",
        EpThemeColor
      );
      for (let i = 1; i <= 2; i++) {
        document.documentElement.style.setProperty(
          `--el-color-primary-dark-${i}`,
          darken(EpThemeColor, i / 10)
        );
      }
      document.documentElement.classList.add(`data-dashboard-${theme}`);
      storageLocal().setItem("dataDashboardThem", theme);
      this.dataDashboardThem = theme;
    },
    /** 修改公共字段 */
    CHANGE_SETTING({ key, value }) {
      if (Reflect.has(this, key)) {
        this[key] = value;
      }
    },
    /** 获取公共字段信息 */
    GET_SETTING(key) {
      if (Reflect.has(this, key)) {
        return this[key];
      } else {
        return null;
      }
    },
    getCloseAutoPopUp() {
      if (!this.closeAutoPopUp) {
        if (!storageLocal().getItem("closeAutoPopUp")) {
          storageLocal().setItem("closeAutoPopUp", false);
        }
        this.closeAutoPopUp = storageLocal().getItem("closeAutoPopUp");
      }
      return this.closeAutoPopUp;
    },
    setCloseAutoPopUp(value) {
      this.closeAutoPopUp = value;
      storageLocal().setItem("closeAutoPopUp", value);
    },
    reDataDashboardThemeStore() {
      let reInfo = {
        dataDashboardThem: null,
        dataDashboardType: 1, //当前大屏类型1:单位大屏 2:项目大屏 3:监管大屏
        dataDashboardMenuId: 1, //当前大屏菜单id
        dataDashboardButtonId: 1, //底部按钮选中id
        dataDashboardProjectId: null, //当前项目id
        dataDashboardIsHidden: 1, //是否隐藏左右两边的内容 1:显示 2:隐藏
        systematicId: null, //系统id
        systemidparent: null, //项目系统父id
        showverviewalrm: 1, //概览告警 1:总览 2:告警
        overviewCenterPoint: [], //监管大屏中心点位
        all: null, //应用系统是否选择全部
        workfresh: 0, //工单刷新
        systemShow: 0, //0:不显示系统选择框 1:显示两级系统选择框 2显示一级系统选择框
        systeminfo: {
          systemName: "",
          selectIndex: "",
          selectIndextwo: "",
          systemlist: [],
          systemlistson: []
        }, //选中的系统信息
        projectInfo: {
          indexMode: 1
        }, //项目背景默认模式 1:地图 2:平面图 3:vr 4
        unityInfo: {
          logo: ""
        }, //项目背景默认模式 1:地图 2:平面图 3:vr 4
        dataDashboardSidebar: {
          id: 1,
          name: null,
          componentleft: "",
          componentright: ""
        }, // //两侧内容

        building: {
          /** 建筑信息 */
          buildingInfo: null,
          /** 当前选中图纸信息 */
          drawingInfo: null,
          /** 当前选中图纸id */
          checkedDrawingId: null
        },

        /** 是否关闭自动弹窗 */
        closeAutoPopUp: false
      };
      for (let key in reInfo) {
        this[key] = reInfo[key];
      }
    },
    //设置地图背景色
    setMapTheme(value) {
      this.mapTheme = value;
      storageLocal().setItem("mapTheme", value);
    },
    //获取地图背景色
    getMapTheme() {
      if (!storageLocal().getItem("mapTheme")) {
        storageLocal().setItem("mapTheme", "darkblue");
        return storageLocal().getItem("mapTheme");
      } else {
        return storageLocal().getItem("mapTheme")
      }
    }
  }
});
function useDataDashboardThemeStoreHook() {
  return useDataDashboardThemeStore(store);
}
export { useDataDashboardThemeStoreHook };
